package cn.pw.test.com.news.adapter;

import android.content.res.Resources;
import android.graphics.Color;
import android.view.View;

import com.aries.ui.view.radius.RadiusTextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;

import cn.pw.test.com.news.R;

public class NewsReportAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    ArrayList<String> strings = new ArrayList<>();

    public NewsReportAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, final String item) {
        Resources res = mContext.getResources();
        RadiusTextView contentTx = helper.itemView.findViewById(R.id.report_item_content_tx);

        contentTx.setText(item);

        if (strings.contains(item)) {
            contentTx.getDelegate().setTextColor(res.getColor(R.color.news_color_text_report_rep));
            contentTx.getDelegate().setBackgroundColor(res.getColor(R.color.news_color_bg_report_rep));
        } else {
            contentTx.getDelegate().setTextColor(res.getColor(R.color.news_color_text_report_nor));
            contentTx.getDelegate().setStrokeColor(res.getColor(R.color.news_color_bg_report_nor));
            contentTx.getDelegate().setBackgroundColor(Color.WHITE);
        }

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (strings.contains(item)) {
                    strings.remove(item);
                } else {
                    strings.add(item);
                }
                notifyDataSetChanged();
            }
        });
    }
}
